package credentials

import (
	. "Go-Easy/pkg/config"
	"context"
	"google.golang.org/grpc/credentials"
)

//生成TLS凭证
func GenerateTLSCredentials() (credentials.TransportCredentials, error) {
	if tls_cred, err := credentials.NewServerTLSFromFile(TLS.CertFile, TLS.KeyFile); err == nil {
		return tls_cred, nil
	} else {
		return nil, err
	}
}

//自定义credentials.PerRPCCredentials()接口
type PerRPCCredential struct {
	Metadata map[string]string
}

//获取请求中的元数据
func (p PerRPCCredential) GetRequestMetadata(ctx context.Context, uri ...string) (map[string]string, error) {
	return p.Metadata, nil
}

//是否开启安全认证
func (p PerRPCCredential) RequireTransportSecurity() bool {
	return false //不开启安全认证
}
